<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>重新支付订单</title>
  <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
  <meta content="yes" name="apple-mobile-web-app-capable"/>
  <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
  <meta content="telephone=no" name="format-detection"/>
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
  <script src="__STATIC__/layer/layer.js"></script>
</head>
<body>
  <form action="{:url('User/repay_order')}" method="post">
    <!--收货地址区 start-->
    <p>收货地址:</p>
      <div>
          <div id="address">
            {if condition="$address_id neq 0"}
                <p id="consignee">{$address.consignee}</p>
                <p id="mobile">{$address.mobile}</p>
                <p id="address">{$address.address}</p>
            {/if}
          </div>
        <a href="javascript:;" onclick="change_address()">选择</a>
      </div>
    <!--收货地址区 end-->

    <!--购买商品区 start-->
      {foreach name="goods" item="v"}
          <img src="{$v.logo}" width="100px;" height="100px;">
          商品名称：<span>{$v.name}</span><br/>
          属性名称：<span>{$v.title}</span><br/>
          商品数量：<span>{$v.goods_num}</span><br/>
          商品总价：<span>{$v.all_amount}</span><br/>
      {/foreach}
    <!--购买商品区 end-->

    <!--配送时间  start-->
    <input type="time" name="delivery_time_1" value="选择时间"> - <input type="time" name="delivery_time_2" value="选择时间"><br/>
    <!--配送时间 end-->

    <!--选择优惠券 start-->
    <div id="chose_coupon">
        <div id="coupon">

        </div>
        <input type="button" value="优惠券" onclick="chose_coupon({$total_amount},{$coupon_cat_id});">
        <input type="button" value="取消" onclick="cancel_coupon();"><br/>
    </div>

    <!--选择优惠券 end-->

    <!--选择代金券 start-->
    <div id="chose_cash_coupon">
        <div id="cash_coupon">

        </div>
        <input type="button" value="代金券" onclick="chose_cash_coupon({$total_amount},{$coupon_cat_id});">
        <input type="button" value="取消" onclick="cancel_cash_coupon();"><br/>
    </div>

    <!--选择代金券 end-->

    <!--选择付款区 start-->
    <div id="pay_type">
        <input type="radio" name="pay_type" value="1" >支付宝<br/>
        <input type="radio" name="pay_type" value="2" >微信<br/>
        <div id="pay_by_credit">
            {if condition="$member.user_money egt $final_amount"}
            <input type="radio" name="pay_type" value="3" >余额<br/>
            {else /}
            <span style="border:1px solid red;">余额不足暂时无法购买</span>
            {/if}
        </div>
    </div>
    <!--选择付款区 end-->

    <!--会员留言区 start-->
    <div>
        <textarea name="user_note">

        </textarea>
    </div>
    <!--会员留言区 end-->

    <!--价格详情区 start-->
    <div>
        <p>金额明细</p>
        <P>商品总价：￥<span id="total_amount">{$total_amount}</span></P>
        <p>运费：￥<span id="delivery_fee">{$delivery_fee}</span></p>
        <p>优惠券：￥<span id="coupon_price">0</span></p>
        <p>合计：￥<span id="final_amount">{$final_amount}</span></p>
    </div>
    <!--价格详情区 end-->
    <!--购物车的商品ID-->
        订单ID：<input type="text" name="id" value="{$id}">
    <!--收货地址id  start-->
        地址id：<input type="text" name="address_id" value="{$address_id}">
    <!--优惠券id  start-->
        优惠券id：<input type="text" name="coupon_id" value="">
    <!--代金券  start-->
        现金券id：<input type="text" name="cash_coupon_id" value="">
    <!--订单运费 start-->
        运费：<input typs="text" name="shipping_price" value="{$delivery_fee}">
    <!--订单原始金额 start-->
        原始总价：<input type="total_amount" name="total_amount" value="{$total_amount}">
    <!--订单原始价格 start-->
        最终支付价：<input type="text" name="final_amount" value="{$final_amount}">
    <!--优惠券抵价 start-->
        优惠券价格：<input type="text" name="coupon_price" value="0">
    <!--现金券抵价 start-->
    现金券价格：<input type="text" name="cash_coupon_price" value="0">
    <br/>
    <input type="submit" value="提交">
</form>
</body>
</html>
<script>
  /*
   * 选择收货地址
   */
  function change_address(){
      var objurl = "{:url('GoodsList/get_address_list')}";
      layer.open({
          type: 2,
          title: '选择收货地址',
          shadeClose: true,
          shade: [0.5, '#666'],
          maxmin: true, //开启最大化最小化按钮
          area: ['600px', '500px'],
          content: objurl
      });
  }
  /**
   * 回调选择父页面的
   * @param  id   选择的地址id
   * @param  consignee  收货人姓名
   * @param  mobile     收货人手机号
   * @param  address    收货人地址
   */
  function select_address(id,consignee,mobile,address){
      layer.closeAll();
      var html = '<p id="consignee">'+consignee+'</p><p id="mobile">'+mobile+'</p><p id="address">'+address+'</p>';
      //查询运费
      $.post("{:url('GoodsList/get_delivery_fee')}",
          {address:address},
          function(data){
              if(data.code == 1){
                  //订单原始支付金额
                  var total_amount = "{$total_amount}";
                  var credit = "{$member.user_money}";      //会员的余额
                  $('#address').html(html);
                  $('input[name=address_id]').val(id);
                  $('input[name=shipping_price]').val(data.data);
                  $('input[name=delivery_fee]').val(data.data);
                  $('#delivery_fee').text(data.data);
                  var final_amount = parseFloat(total_amount) + parseFloat(data.data);
                  $('#final_ampont').text(final_amount);
                  $('input[name=final_amount]').val(final_amount);
                  if(credit < final_amount){
                      $('#pay_by_credit').html('<span style="border:1px solid red;">余额不足暂时无法购买</span>');
                  }else{
                      $('#pay_by_credit').html('<input type="radio" name="pay_type" value="3" >余额<br/>');
                  }
              }else{
                  alert(data.msg);
                  $('input[name=address_id]').val();
              }
          }

      );
//        location.reload();
  }

  /**
   *  选择优惠券 -- 门店关注券、普通优惠券
   *  @param   total_amount  订单总金额
   *  @param   cate_id   商品分类id
   */
  function chose_coupon(total_amount,cate_id){
      var objurl = "{:url('GoodsList/get_coupon_list')}?total_amount="+total_amount+"&cate_id="+cate_id;
      layer.open({
          type: 2,
          title: '选择优惠券',
          shadeClose: true,
          shade: [0.5, '#666'],
          maxmin: true, //开启最大化最小化按钮
          area: ['600px', '500px'],
          content: objurl
      });
  }
  /**
   * 选择会员普通优惠券
   */
  function select_coupon(id,logo,reduce,morethan){
      layer.closeAll();
      var html = '<img class="logo" src="'+logo+'" width="80px;" height="80px;">抵价金额：<span class="reduce">'+reduce+'</span>满减条件：<span class="morethan">'+morethan+'</span>';
      //商品原始总价
      var total_amount = "{$total_amount}";
      total_amount = parseFloat(total_amount);
      var credit = "{$member.user_money}";      //会员的余额
      //订单运费
      var delivery_fee = parseFloat($('input[name=shipping_price]').val());
      //优惠券抵金额
      var reduce = parseFloat(reduce);
      $('input[name=coupon_id]').val(id);
      $('input[name=coupon_price]').val(reduce);
      $('#coupon_price').text(reduce);
      var final_amount = total_amount+delivery_fee-reduce;
      $('#final_amount').text(final_amount);
      $('input[name=final_amount]').val(final_amount);
      $('#coupon').html(html);
      $('#chose_cash_coupon').css('display','none');
      //判断是否可以进行余额支付
      if(credit < final_amount){
          $('#pay_by_credit').html('<span style="border:1px solid red;">余额不足暂时无法购买</span>');
      }else{
          $('#pay_by_credit').html('<input type="radio" name="pay_type" value="3" >余额<br/>');
      }
  }
  /**
   * 取消优惠券
   */
  function cancel_coupon(){
      var coupon_price = parseFloat($('input[name=coupon_price]').val());
      var final_amount = parseFloat($('input[name=final_amount]').val());
      var credit = "{$member.user_money}";      //会员的余额
      final_amount = final_amount+coupon_price;
      $('input[name=coupon_price]').val('0');
      $('input[name=final_amount]').val(final_amount);
      $('#final_amount').text(final_amount);
      $('#coupon_price').text(0);
      $('#coupon').html('');
      $('input[name=coupon_id]').val('');
      $('#chose_cash_coupon').css('display','block');
      //判断是否可以进行余额支付
      if(credit < final_amount){
          $('#pay_by_credit').html('<span style="border:1px solid red;">余额不足暂时无法购买</span>');
      }else{
          $('#pay_by_credit').html('<input type="radio" name="pay_type" value="3" >余额<br/>');
      }
  }

  /**
   * 选择门店代金券
   */
  function chose_cash_coupon(total_amount,cate_id){
      var objurl = "{:url('GoodsList/get_cash_coupon')}?total_amount="+total_amount+"&cate_id="+cate_id;
      layer.open({
          type: 2,
          title: '选择代金券',
          shadeClose: true,
          shade: [0.5, '#666'],
          maxmin: true, //开启最大化最小化按钮
          area: ['600px', '500px'],
          content: objurl
      });
  }

  /**
   * 选择门店代金券
   */
  function select_cash_coupon(id,logo,reduce,morethan){
      layer.closeAll();
      var html = '<img class="logo" src="'+logo+'" width="80px;" height="80px;">抵价金额：<span class="reduce">'+reduce+'</span>购买价格：<span class="morethan">'+morethan+'</span>';
      //商品原始总价
      var total_amount = "{$total_amount}";
      var credit = "{$member.user_money}";      //会员的余额
      total_amount = parseFloat(total_amount);
      //订单运费
      var delivery_fee = parseFloat($('input[name=shipping_price]').val());
      //优惠券抵金额
      var reduce = parseFloat(reduce);
      $('input[name=cash_coupon_id]').val(id);
      $('input[name=cash_coupon_price]').val(reduce);
      $('#coupon_price').text(reduce);
      var final_amount = total_amount+delivery_fee-reduce;
      $('#final_amount').text(final_amount);
      $('input[name=final_amount]').val(final_amount);
      $('#cash_coupon').html(html);
      $('#chose_coupon').css('display','none');//判断是否可以进行余额支付
      if(credit < final_amount){
          $('#pay_by_credit').html('<span style="border:1px solid red;">余额不足暂时无法购买</span>');
      }else{
          $('#pay_by_credit').html('<input type="radio" name="pay_type" value="3" >余额<br/>');
      }

  }
  /**
   * 取消优惠券
   */
  function cancel_cash_coupon(){
      var cash_coupon_price = parseFloat($('input[name=cash_coupon_price]').val());
      var final_amount = parseFloat($('input[name=final_amount]').val());
      var credit = "{$member.user_money}";      //会员的余额
      final_amount = final_amount+cash_coupon_price;
      $('input[name=cash_coupon_price]').val('0');
      $('input[name=final_amount]').val(final_amount);
      $('#final_amount').text(final_amount);
      $('#coupon_price').text(0);
      $('#cash_coupon').html('');
      $('input[name=cash_coupon_id]').val('');
      $('#chose_coupon').css('display','block');
      //判断是否可以进行余额支付
      if(credit < final_amount){
          $('#pay_by_credit').html('<span style="border:1px solid red;">余额不足暂时无法购买</span>');
      }else{
          $('#pay_by_credit').html('<input type="radio" name="pay_type" value="3" >余额<br/>');
      }
  }

  /**
   *  检查预支付订单
   */
  function checkform(){
      var address_id = $('input[name=address_id]').val();
      if(address_id == ''){
          alert('请选择收货地址');
          return false;
      }
      return true;
  }
</script>